/************************************************/
/*    Auteur    : Yoann NICOD                   */
/*    Programme : Atomic Bomberman Origins      */
/*    Fichier   : application.cpp               */
/*    Date      : 18/11/2012                    */
/************************************************/

#include <iostream>
#include "debug.h"
#include "application.h"

Application::Application(void) : m_App(sf::VideoMode(800, 600, 32), "Atomic Bomberman Origins"/*, Style::Fullscreen*/)
//Application::Application(void) : m_App(sf::VideoMode(800, 600, 32), "Atomic Bomberman Origins", Style::Fullscreen)
{
	m_pServeur = NULL;

	Log("Ouverture de la fenetre...", 1);
}

Application::~Application(void)
{
//	Log("Fermeture de la fenetre...", 1);
}

void Application::Run()
{
	int ID = 0;

	VueChargement MaVueChargement(&m_App);
	m_Fenetre.Push(&MaVueChargement);

//	VueMenuPrincipal MaVueMenuPrincipal(&m_App);
//	m_Fenetre.Push(&MaVueMenuPrincipal);

	while(m_App.IsOpened())
	{
		Event Event;
		while (m_App.GetEvent(Event))
		{
			if(Event.Type == Event::KeyPressed && Event.Key.Code == Key::A)
				ID = m_ModuleAudio.JouerSon(0, false);

			if(Event.Type == Event::KeyPressed && Event.Key.Code == Key::B)
				m_pServeur = new Serveur();

			if(Event.Type == Event::KeyPressed && Event.Key.Code == Key::C)
				delete m_pServeur;

			if(Event.Type == Event::KeyPressed && Event.Key.Code == Key::D)
			{
				Packet MonPaquet;
				MonPaquet << "coucou"; 
				m_pServeur->EnvoyerATous(MonPaquet);
			}

			if (Event.Type == Event::Closed)
				m_App.Close();

			if ((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape))
				m_App.Close();
		}

		m_App.Clear();
		m_Fenetre.EffectuerRendu();
		m_App.Display();
	}

	return;
}